package com.nulldev.util.web.nTubeExtensions.services.Unspotified;

import java.io.InputStream;

import com.nulldev.util.web.HttpClient.HttpClient;
import com.nulldev.util.web.HttpClient.HttpMethod;
import com.nulldev.util.web.HttpClient.HttpResponse;
import com.nulldev.util.web.HttpServer3.Response;
import com.nulldev.util.web.HttpServer3.pages.v3.HttpPage3;

public class WidevineLicenseProxyPage extends HttpPage3 {

	public WidevineLicenseProxyPage(String id) {
		super("/melody/v1/license_url");
	}

	public static final String PRE_FLIGHT_URL = "https://gew1-spclient.spotify.com/melody/v1/license_url";

	@Override
	public Response onRequest(final Request request) {
		final String args = request.url();
		final String authHeader = request.header("Authorization", null);
		if (authHeader == null) {
			return fail(401);
		}
		try {
			final HttpResponse<InputStream> is = HttpClient.getStream().url(PRE_FLIGHT_URL + args).header("Origin", "https://open.spotify.com")
					.header("Referer", "https://open.spotify.com").create(HttpMethod.GET);
		} catch (Exception e) {
			fail();
		}
		return null;
	}

}
